/**
 * Copyright Facebook Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @provides fb.console
 */

$ = function(i) { return document.getElementById(i); };

function friendsList(){

  //Obtenemos la gente que nos pasaron por parametros en la lista hidden
  var people = $('#people li');
  var getValue =  function(x){ return x.value };
  people = jQuery.map(people, getValue);
  //aca nose porq hay un error si value en li tiene un valor muy grande por ej: 100001091211145

  var status = document.getElementById('info');

  var list = document.getElementById('sortable1');

  //uid del que esta logueado
  var fb_uid = 0;

  FB.getLoginStatus(function(response) {

    if (response.status != 'connected'){
      status.innerHTML = 'You are not connected';
      return;
    }

    console.debug('friends.get response '+ people.toString());

    var numFriends = people.length;

    var friends = 'Grupos en el match';

    //saquemos el fb_uid del que esta logueado para no meterlo en el ranking
    FB.api('/me', function(response) {
      fb_uid = response.id;

      if (numFriends > 0) {
        for (var i=0; i<numFriends; i++) {
          
          if(fb_uid != people[i]){
            friends += (
              '<li class="ui-state-default">' +
                '<input type="hidden" name="uid" value="' + people[i] + '">' +
                '<img src="https://graph.facebook.com/' + people[i] + '/picture"/>' +
      			        '</fb:profile-pic>' +
                    '<br>' +
                    '<fb:name linked="false" firstnameonly="true" uid="' + people[i] + '" />' +
              '</li>'
            );
          }
        }
              
        list.innerHTML = friends;
        FB.XFBML.parse(list);

      }

    });
  });
}
